<template>
    <div id="login">
        <div class="login">
            <input id="Id" style="margin-top:26em;" type="text" placeholder="学号：" v-model="id"><br><br>
            <input id="Pw"type="password" placeholder="密码：" v-model="Pw"><br><br>
            <input type="button" value="登录" @click="login">
        </div>
              <router-view></router-view>
        <div @click="toRegistr" style="margin-top:15%;margin-left:60%;text-decoration: underline;">点此注册..</div>
    </div>
</template>

<script>
    import axios from 'axios'
import {mapMutations} from "vuex"
    export default {
        name: 'app',
        data () {

            return {
                id: "",
                Pw: "",
            }
        },
        methods: {

             toRegistr:function () {


                 this.$store.commit("changeStyle",6);
                 this.$router.push('/login/registr')

            },
            ...mapMutations([
                'changeBtn' // 映射 this.increment() 为 this.$store.commit('increment')
            ]),
            login: function() {
                var params = new URLSearchParams();
                params.append('id',this.id );
                params.append('Pw',this.Pw );
                var _this = this
                axios.post('/users/login',params).then(function (res) {
                    if(res.data.result==0) {
                       alert('用户不存在')
                   }else if(res.data.result==1){
                        alert('成功')
                        console.log(res.data);
                        _this.changeBtn();
                        _this.$router.push({path:'/my/my_1',query:{user:res.data.user,id:res.data.id}})
                   }else {
                        alert('密码错了')
                   }
//                    _this.$router.push({path:'/my'})

                }).catch(function (err) {
                    console.log(err);
                })
                /* if(res.data.result){
                 alert('注册成功')
                 }else{
                 alert("404")
                 }*/


            }



        },


    }
</script>

<style>




</style>